package com.silp.labs.cacticlient;

import android.app.Activity;
import android.app.ListActivity;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Treedata_Listview extends Activity {
	public TreeData[] treedata ;
	public int ntreelenght;
	public ArrayAdapter<String> adaptertree;
	ArrayAdapter<String> adaptertree1;
	public ListView mlv;
	@Override
	protected void onCreate(Bundle ibundle) {
		// TODO Auto-generated method stub
		super.onCreate(ibundle);
		setContentView(R.layout.tree_layout);
		Bundle extra =getIntent().getExtras();
		String tree_data = (String)extra.get("treedata");
		treedata = new TreeData[100];
		 ntreelenght = 0;
		ntreelenght = ProcessData.ProcessDataTree(tree_data, treedata, ntreelenght);
		String[] aa = TreeData.getTreeListName(treedata, ntreelenght);
		 mlv =(ListView) findViewById(R.id.lv_tree);
		 adaptertree1=new ArrayAdapter<String>(this,
	                android.R.layout.simple_list_item_1,new String[]{""});

		  adaptertree = new ArrayAdapter<String>(this,
		                android.R.layout.simple_list_item_1, aa);
		
		mlv.setAdapter(adaptertree);
		
		mlv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
			
				String strItem = ((TextView) arg1).getText().toString();
				int ka = TreeData.GetTreeIndex(treedata, ntreelenght, strItem);
				TreeData sa = treedata[ka];
				String[] aa1 = sa.getHostList();
				
				//Toast.makeText(getApplicationContext(), aa1[2], 100).show();
				 
				//adaptertree.notifyDataSetChanged();
				//adaptertree.clear();
				//Intent hostIntent = new Intent(getApplicationContext(), Hostdata_Listview.class);
				for (int i = 0; i < aa1.length; i++) {
					String string =aa1[i];
					//hostIntent.putExtra("hostdata", aa1[i]);
					Toast.makeText(getApplicationContext(), string, 100).show();
					
				}
				//startActivity(hostIntent);
			}
		});
	}


}
